// 导入路由
import router from './router'
import store from './store'
//  获取token
// 路由前置守卫
router.beforeEach((to, from, next) => {
  const token = store.state.user.userDate.token
  // console.log(token)
  // 设置白名单
  const bai = ['/login', '*']
  // 判断
  if (token) {
    // 有就都可以去
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
    next()
  } else {
    // 有一点小bag
    if (bai.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
